package io.writeFile;

import java.io.*;

/**
 * 读取文件中的数据到另外的文件
 * 方法1：按行字符读取
    1.创建文件输入流
    2.创建字符输入流
    3.创建缓存字符输出流
 */
public class ReadFileToOther {
    public static void main(String[] args) throws IOException {
        FileInputStream fis = new FileInputStream("./other/src/io/writeFile/old.txt");
        InputStreamReader isr = new InputStreamReader(fis);
        BufferedReader br=new BufferedReader(isr);

        FileOutputStream fos = new FileOutputStream("./other/src/io/writeFile/new.txt", false);
        OutputStreamWriter osw = new OutputStreamWriter(fos);
        BufferedWriter bw = new BufferedWriter(osw);

        String content;
        //可以一次性读取到再写
        StringBuffer sb = new StringBuffer();
        while ((content = br.readLine()) != null) {
            System.out.println(content);
            bw.write(content);
            bw.newLine();
            bw.flush();
        }

        bw.close();
        osw.close();
        fos.close();

        br.close();
        isr.close();
        fis.close();
    }
}
